package com.hypertian.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.hypertian.demo.view.progress.view.PikerSeekBarView;

public class MainActivity extends AppCompatActivity {

    private int mCurrValue = 50;
    private int mMaxValue = 100;
    private int mMinValue = 0;

    PikerSeekBarView mPikerSeekBarView;
    TextView mHeightValue;
    EditText etCurrValue, etMinValue, etMaxValue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);

        mHeightValue = (TextView) findViewById(R.id.tv_user_height_value);
        etCurrValue = (EditText) findViewById(R.id.et_curr_value);
        etMinValue = (EditText) findViewById(R.id.et_min_value);
        etMaxValue = (EditText) findViewById(R.id.et_max_value);

        mHeightValue.setText((int) mCurrValue + "%");

        mPikerSeekBarView = (PikerSeekBarView) findViewById(R.id.scaleWheelView_height);
        mPikerSeekBarView.initValue(mCurrValue, mMaxValue, mMinValue);
        mPikerSeekBarView.setValueChangeListener(new PikerSeekBarView.OnValueChangeListener() {
            @Override
            public void onValueChange(int value) {
                mHeightValue.setText(value + "%");
                mCurrValue = value;
            }
        });

        findViewById(R.id.bt_sub).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int curr, min, max;
                try {
                    curr = Integer.parseInt(etCurrValue.getText().toString());
                    min = Integer.parseInt(etMinValue.getText().toString());
                    max = Integer.parseInt(etMaxValue.getText().toString());
                    mPikerSeekBarView.initValue(curr, max, min);
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "请输入完整", Toast.LENGTH_SHORT).show();
                }
            }
        });
        findViewById(R.id.bt_set_curr_value).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int curr;
                try {
                    curr = Integer.parseInt(etCurrValue.getText().toString());
                    mPikerSeekBarView.setCurrValue(curr);
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "请输入当前进度", Toast.LENGTH_SHORT).show();
                }
            }
        });
        findViewById(R.id.bt_set_min_value).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int min;
                try {
                    min = Integer.parseInt(etMinValue.getText().toString());
                    mPikerSeekBarView.setMinValue(min);
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "请输入最小值", Toast.LENGTH_SHORT).show();
                }
            }
        });
        findViewById(R.id.bt_set_max_value).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int max;
                try {
                    max = Integer.parseInt(etMaxValue.getText().toString());
                    mPikerSeekBarView.setMaxValue(max);
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "请输入最大值", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
